package com.forward.eventdemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity
        implements View.OnClickListener, View.OnTouchListener, View.OnLongClickListener {
    private static final String TAG = "MainActivity";
    private TextView mTextView;
    private MyRelativeLayout mLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mTextView = (MyTextView)findViewById(R.id.my_text_view);
        mLayout = (MyRelativeLayout)findViewById(R.id.my_layout);
        mTextView.setOnClickListener(this);
        mTextView.setOnTouchListener(this);
        mTextView.setOnLongClickListener(this);
        mLayout.setOnClickListener(this);
        mLayout.setOnTouchListener(this);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                Log.i("ljh", TAG + " dispatchTouchEvent ACTION_DOWN");
                break;
            case MotionEvent.ACTION_UP:
                Log.i("ljh", TAG + " dispatchTouchEvent ACTION_UP");
                break;
            case MotionEvent.ACTION_MOVE:
                Log.i("ljh", TAG + " dispatchTouchEvent ACTION_MOVE");
                break;
            case MotionEvent.ACTION_CANCEL:
                Log.i("ljh", TAG + " dispatchTouchEvent ACTION_CANCEL");
                break;

        }
        boolean dispatchTouchEvent = super.dispatchTouchEvent(event);
//        Log.i("ljh",TAG+" dispatchTouchEvent " + dispatchTouchEvent);
        return dispatchTouchEvent;
//        return false;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                Log.i("ljh", TAG + " onTouchEvent ACTION_DOWN");
                break;
            case MotionEvent.ACTION_UP:
                Log.i("ljh", TAG + " onTouchEvent ACTION_UP");
                break;
            case MotionEvent.ACTION_MOVE:
                Log.i("ljh", TAG + " onTouchEvent ACTION_MOVE");
                break;
            case MotionEvent.ACTION_CANCEL:
                Log.i("ljh", TAG + " onTouchEvent ACTION_CANCEL");
                break;

        }
        return super.onTouchEvent(event);
//        return true;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.my_text_view:
                Log.i("ljh","MyTextView onclick");
                break;
            case R.id.my_layout:
                Log.i("ljh","mLayout onclick");
                break;
        }
    }

    @Override
    public boolean onTouch(View view, MotionEvent event) {
        switch (view.getId()){
            case R.id.my_text_view:
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        Log.i("ljh", "MyTextView onTouch ACTION_DOWN");
                        break;
                    case MotionEvent.ACTION_UP:
                        Log.i("ljh", "MyTextView onTouch ACTION_UP");
                        break;
                    case MotionEvent.ACTION_MOVE:
                        Log.i("ljh", "MyTextView onTouch ACTION_MOVE");
                        break;
                    case MotionEvent.ACTION_CANCEL:
                        Log.i("ljh",  "MyTextView onTouch ACTION_CANCEL");
                        break;

                }
                break;
            case R.id.my_layout:
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        Log.i("ljh", "mLayout onTouch ACTION_DOWN");
                        break;
                    case MotionEvent.ACTION_UP:
                        Log.i("ljh", "mLayout onTouch ACTION_UP");
                        break;
                    case MotionEvent.ACTION_MOVE:
                        Log.i("ljh", "mLayout onTouch ACTION_MOVE");
                        break;
                    case MotionEvent.ACTION_CANCEL:
                        Log.i("ljh",  "mLayout onTouch ACTION_CANCEL");
                        break;

                }
                break;
        }
        return false;
    }

    @Override
    public boolean onLongClick(View v) {
        Log.i("ljh","MyTextView onLongClick");
        return false;
    }
}
